package com.hunau.novel_reading.controller;

import com.hunau.novel_reading.common.R;
import com.hunau.novel_reading.request.HistoryInsertReq;
import com.hunau.novel_reading.request.HistorySeekByUserId;
import com.hunau.novel_reading.request.HistorySeekReq;
import com.hunau.novel_reading.service.HistoryService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/history")
public class HistoryController {
    @Resource
    private HistoryService historyService;
    @RequestMapping("/seek")
    public R seek(@RequestBody @Valid HistorySeekReq historySeekReq)
    {
        return R.ok().data("books",historyService.selectBooksByUsername(historySeekReq));
    }
    @RequestMapping("/insert")
    public R insert(@RequestBody @Valid HistoryInsertReq historyInsertReq)
    {
        System.out.println(historyInsertReq);
        if (historyService.insertHistoryRecordByUserAndBookName(historyInsertReq) == 1)
            return R.ok().message("插入成功");
        else
            return R.error().message("插入失败");
//        return R.ok().data("insert",historyService.insertHistoryRecordByUserAndBookName(historyInsertReq));
    }
    @RequestMapping("/seekByUserId")
    public R seekByUserId(@RequestBody @Valid HistorySeekByUserId historySeekByUserId)
        {
            return R.ok().data("books",historyService.selectBooksByUserId(historySeekByUserId.getUserId()));
        }
}
